from lxml import etree
import os
"""该文件用于调试xpath语句"""
"""用法：
    由于chrome inspect中不便于调试xpath，可以打印出页面源码粘贴至demo.HTML中，再用该脚本调试即可。"""


dir = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(dir, "demo.HTML"), "r") as f:
    html = etree.HTML(f.read())

# =========================================================
# 在这里写xpath语法即可

locater = "//wx-view[@class='comment-list-content']//wx-view[@class='comment-content']/wx-text/span[@style='display:none;']"

# =========================================================

data = html.xpath(locater)
print(data)

print("元素详细内容：")
for d in data:
    print(etree.tostring(d))
    print(d.text)